const button = document.getElementById('btn');
let leaveNotification;

button.addEventListener('click', async () => {
	const permission = await Notification.requestPermission();

    if (permission === 'granted') {
        const notification = new Notification('球球的前端奶茶屋', {
            body: '求三连～',
            data: {
                address: 'https://space.bilibili.com/25424697'
            },
            icon: 'https://static.animpen.com/u/320/icon/bilibili-app.png',
            // tag: 'bilibili',
            // requireInteraction: true,
        });
        notification.addEventListener('close', e => {
            console.log(e);
        });
    }
});

document.addEventListener('visibilitychange', () => {
    if (document.visibilityState === 'hidden') {
        leaveNotification = new Notification('快回来');
    } else {
        leaveNotification.close();
    }
});